#!/usr/bin/env python3
import os
import django

# 设置Django环境
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'wealth_backend.settings')
django.setup()

from users.models import User
from rest_framework.authtoken.models import Token

# 创建测试用户
user, created = User.objects.get_or_create(
    username='testuser',
    defaults={'email': 'test@test.com'}
)

if created:
    user.set_password('testpass')
    user.save()
    print(f'Created new user: {user.username}')
else:
    print(f'User already exists: {user.username}')

# 获取或创建token
token, created = Token.objects.get_or_create(user=user)
print(f'Token: {token.key}')